package com.vlin.token.defaut;

import com.vlin.api.client.ApiClient;
import com.vlin.api.client.request.ParamsProducer;
import com.vlin.token.AbstractTokenManager;
import com.vlin.token.Token;
import com.vlin.token.TokenCache;
import com.vlin.token.TokenRefresher;


public class DefaultTokenManager extends AbstractTokenManager {
	
	private TokenCache tokenCache = new DefaultTokenCache();
	
	private TokenRefresher tokenRefresher = new DefaultTokenRefresher();
	
	private ApiClient apiClient;
	
	private String defaultTokenKey;

	@Override
	public void setTokenCacheManager(TokenCache manager) {
		this.tokenCache = manager;
	}

	@Override
	public TokenCache getTokenCacheManager() {
		
		return this.tokenCache;
	}

	@Override
	public boolean useTokenCache() {
		
		return tokenCache != null;
	}

	@Override
	public void setTokenRefresher(TokenRefresher tokenRefresher) {
		this.tokenRefresher = tokenRefresher;
		if(this.apiClient != null) {
			this.tokenRefresher.setApiClient(apiClient);
		}
	}

	@Override
	public TokenRefresher getTokenRefresher() {
		
		return this.tokenRefresher;
	}

	@Override
	public void setApiClient(ApiClient apiClient) {
		this.apiClient = apiClient;
		if(this.tokenRefresher != null) {
			this.tokenRefresher.setApiClient(apiClient);
		}
	}

	@Override
	public ApiClient getApiClient() {
		return this.apiClient;
		
	}

	@Override
	public String getDefaultTokenKey() {
		
		return this.defaultTokenKey;
	}

	@Override
	public void setDefaultTokenKey(String key) {
		this.defaultTokenKey = key;
		
	}

	@Override
	public Token getToken() {
		
		return getToken(defaultTokenKey);
	}

	@Override
	public void setParamsProduer(ParamsProducer paramsProducer) {
		this.tokenRefresher.setParamsProduer(paramsProducer);
		
	}
	

}
